package com.ai.service.made.impl;

import com.ai.entity.made.Slabs;
import com.ai.mapper.made.SlabsMapper;
import com.ai.service.made.ISlabsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.nio.file.Path;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chen
 * @since 2023-03-28 11:12:30
 */
@Service
public class SlabsServiceImpl extends ServiceImpl<SlabsMapper, Slabs> implements ISlabsService {

    /**
     * 判断板坯号是否存在
     *
     * @param slabNum
     * @return
     */
    @Override
    public boolean isExist(String slabNum) {
        return count(new QueryWrapper<Slabs>().eq("slab_num", slabNum)) > 0;
    }

    /**
     * 图片下载之后，将路径信息更新到数据库记录
     * @param toPath
     * @param pictureId
     */
    @Override
    public void updateDownloadUPdPicture(Path toPath, String pictureId) {
        update(new UpdateWrapper<Slabs>().eq("id",pictureId)
                .set("up_picture_local_url",toPath.toString())
                .set("up_local_flag","1"));
    }

    @Override
    public void updateDownloadLOWERPicture(Path toPath, String pictureId) {
        update(new UpdateWrapper<Slabs>().eq("id",pictureId)
                .set("lower_picture_local_url",toPath.toString())
                .set("lower_local_flag","1"));
    }
}
